#include "LoginDataWidget.h"
#include "ui_LoginDataWidget.h"


LoginDataWidget::LoginDataWidget(QWidget *parent) :
    QWidget(parent), ui(new Ui::LoginDataWidget)
{
    ui->setupUi(this);
    OnConnect();
}

LoginDataWidget::~LoginDataWidget()
{
    delete ui;
}

void LoginDataWidget::SetNetworkList(const QStringList &list) const
{
   ui->comboBox_network_list->addItems(list);
}

int LoginDataWidget::GetCurentNetworkIndex() const
{
    return ui->comboBox_network_list->currentIndex();
}

void LoginDataWidget::OnConnect()
{
    connect(ui->toolButton_start, &QToolButton::clicked, this, &LoginDataWidget::OnStartClick);
    connect(ui->toolButton_clear, &QToolButton::clicked, this, &LoginDataWidget::OnClearClick);
}

void LoginDataWidget::OnStartClick(const bool checked)
{
    if (checked)
    {
        ui->toolButton_start->setIcon(QIcon(":/svg/play_green.svg"));
        ui->toolButton_start->setToolTip("停止");
        ui->textEdit->append("服务启动 ... ");
    }
    else
    {
        ui->toolButton_start->setIcon(QIcon(":/svg/play.svg"));
        ui->toolButton_start->setToolTip("开始");
        ui->textEdit->append("服务停止！ ");
    }

    emit StartServer(checked);
}

void LoginDataWidget::OnClearClick() const
{
    ui ->textEdit->clear();
}

void LoginDataWidget::AddLog(const QString &msg) const
{
    ui->textEdit->append(msg);
}
